package com.midea.jdk8.lambda;

import org.junit.Test;

import java.util.Comparator;


/**
 * @Author: Mr.Wang
 * @Description:
 * @Date: Create in 18:06 2021/12/18
 */
public class LambdaTest {
    @Test
    public void test1(){

        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("我爱北京天安门");
            }
        };
        r1.run();
        System.out.println("**********");
        Runnable r2 = () -> System.out.println("我爱上海");
        r2.run();
    }

    @Test
    public void test2(){
        //原生写法
        Comparator<Integer> com1 = new Comparator<Integer>(){
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };
        System.out.println(com1.compare(21,32));
        //lambda表达式写法
        Comparator<Integer> com2 = (Integer o1,Integer o2) -> Integer.compare(o1,o2);
        System.out.println("**********");
        System.out.println(com2.compare(21,32));
        System.out.println("**********");
        //方法引用
        Comparator<Integer> com3 =  Integer :: compare;
        System.out.println(com2.compare(21,32));
    }



}
